package probe.logic;
/* 
 * Task class : to store a task
 */
public class Task implements Comparable<Task> {

	private static final String TASKSTATUS_UNFINISHED = "UNFINISHED";
	private static final String TASKSTATUS_DONE = "DONE";

	public static enum TaskStatus {
		UNFINISHED, DONE
	}

	public enum TaskType {
		FLOATING_TASK, DEADLINE_TASK, STET_TASK
	}

	public TaskStatus taskStatus;
	public TaskType taskType;
	public Date deadline;
	public Date startingDate;
	public Date endingDate;
	public Time startingTime;
	public Time endingTime;
	public Time time;
	public String taskName;

	public static TaskStatus findTaskStatus(String status) {

		if (status == null)
			return null;

		if (status.equalsIgnoreCase(TASKSTATUS_UNFINISHED)) {
			return TaskStatus.UNFINISHED;
		} else if (status.equalsIgnoreCase(TASKSTATUS_DONE)) {
			return TaskStatus.DONE;
		} else {
			return null;
		}
	}

	@Override
	public String toString() {
		return this.taskName;
	}

	public Task(String taskName, Date deadline, Time time, TaskStatus status) {

		this.taskType = TaskType.DEADLINE_TASK;
		this.taskStatus = status;
		this.taskName = taskName;
		this.deadline = deadline;
		this.startingDate = null;
		this.endingDate = null;
		this.time = time;
		this.startingTime = null;
		this.endingTime = null;
	}

	public Task(String taskName, TaskStatus status) {
		this.taskType = TaskType.FLOATING_TASK;
		this.taskStatus = status;
		this.taskName = taskName;
		this.deadline = null;
		this.startingDate = null;
		this.endingDate = null;
		this.time = null;
	}

	public Task(String taskName, Date startingDate, Date endingDate,
			Time startingTime, Time endingTime, TaskStatus status) {
		this.taskType = TaskType.STET_TASK;
		this.taskStatus = status;
		this.taskName = taskName;
		this.deadline = null;
		this.startingDate = startingDate;
		this.endingDate = endingDate;
		this.time = null;
		this.startingTime = startingTime;
		this.endingTime = endingTime;
	}

	public Task() {

	}

	@Override
	public int compareTo(Task anotherTask) {
		if (anotherTask.taskType == TaskType.FLOATING_TASK){
			if (this.taskType == TaskType.FLOATING_TASK){
				return this.taskName.compareTo(anotherTask.taskName);
			}
			else
				return 1;
		}
		
		if (this.taskType == TaskType.FLOATING_TASK)
			return -1;
		
		Date date1;
		Date date2;
		if (this.taskType == TaskType.DEADLINE_TASK)
			date1 = this.deadline;
		else date1 = this.startingDate;
		if (anotherTask.taskType == TaskType.DEADLINE_TASK)
			date2 = anotherTask.deadline;
		else date2 = anotherTask.startingDate;
		if (date1 == date2)
			return this.taskName.compareTo(anotherTask.taskName);
		
		return (date1.compareTo(date2));
	}
	
}
